package com.ocean.service.library.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ocean.dao.library.CategoryDao;
import com.ocean.dao.library.RuleDao;
import com.ocean.entity.library.Category;
import com.ocean.entity.library.Rule;
import com.ocean.service.library.RuleService;
import com.ocean.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

/**
 * Project：SchoolManage
 * Package：com.ocean.service.library.impl
 * Author:zy
 * Time:2023/3/3
 */

@Service
public class RuleServiceImpl implements RuleService {

    @Autowired
    private RuleDao ruleDao;

    @Override
    public R save(Rule rule) {
        if (ruleDao.insert(rule) > 0) {
            return R.ok();
        } else {
            return R.fail("插入规则失败");
        }
    }

    @Override
    public R queryPage(int page, int size, Integer days, BigDecimal rules) {
        PageHelper.startPage(page, size);
        PageInfo<Rule> pageInfo = new PageInfo<Rule>(ruleDao.selectAllByCondition(days,rules));
        return R.ok(pageInfo);
    }


    @Override
    public R delete(int id) {
        if(ruleDao.delete(id)>0){
            return R.ok();
        }else {
            return R.fail();
        }
    }

    @Override
    public R update(Rule rule) {
        return R.ok(ruleDao.update(rule));
    }
}

